﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using System.Data;

namespace BLL
{
    public class PersonInfoBO
    {
        public PersonInfoBO() { }

        PersonInfoDAO dao = new PersonInfoDAO();


        //public DataSet YyCount(string fromusername)
        //{
        //    return dao.YyCount(fromusername);
        //}


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(PersonInfo model)
        {
            return dao.Add(model);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(PersonInfo model)
        {
           return dao.Update(model);
        }



        public int Update(int ID, string WXName)
        {
            return dao.Update(ID, WXName);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {
            dao.Delete(ID);
        }

        /// <summary>
        /// 根据微信号得到数据
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public int GetByFromUserName(string userid)
        {
            return dao.GetByFromUserName(userid);
        }



        public DataSet GetNameByFromUserName(string userid)
        {
            return dao.GetNameByFromUserName(userid);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PersonInfo GetModel(int ID)
        {
            return dao.GetModel(ID);
        }

        /// <summary>
        /// 得到一个对象实体  微信号
        /// </summary>
        public PersonInfo GetModel(string FromUserName)
        {
            return dao.GetModel(FromUserName);
        }

        /// <summary>
        /// 得到一个对象实体 姓名，手机
        /// </summary>
        public PersonInfo GetModel(string Name, string Phone)
        {
            return dao.GetModel(Name, Phone);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dao.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PersonInfo> GetModelList(string strWhere)
        {
            DataSet ds = dao.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<PersonInfo> DataTableToList(DataTable dt)
        {
            List<PersonInfo> modelList = new List<PersonInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                PersonInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new PersonInfo();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    model.Name = dt.Rows[n]["Name"].ToString();
                    if (dt.Rows[n]["Sex"].ToString() != "")
                    {
                        if ((dt.Rows[n]["Sex"].ToString() == "1") || (dt.Rows[n]["Sex"].ToString().ToLower() == "true"))
                        {
                            model.Sex = true;
                        }
                        else
                        {
                            model.Sex = false;
                        }
                    }
                    model.Phone = dt.Rows[n]["Phone"].ToString();
                    if (dt.Rows[n]["BIRTHDAY"].ToString() != "")
                    {
                        model.BIRTHDAY = DateTime.Parse(dt.Rows[n]["BIRTHDAY"].ToString());
                    }
                    model.EMAIL = dt.Rows[n]["EMAIL"].ToString();
                    model.area = dt.Rows[n]["area"].ToString();
                    model.addr = dt.Rows[n]["addr"].ToString();
                    model.PersonNo = dt.Rows[n]["PersonNo"].ToString();
                    if (dt.Rows[n]["MEM_DATE"].ToString() != "")
                    {
                        model.MEM_DATE = DateTime.Parse(dt.Rows[n]["MEM_DATE"].ToString());
                    }
                    model.MEM_LEVEL = dt.Rows[n]["MEM_LEVEL"].ToString();
                    if (dt.Rows[n]["WX_DATE"].ToString() != "")
                    {
                        model.WX_DATE = DateTime.Parse(dt.Rows[n]["WX_DATE"].ToString());
                    }
                    if (dt.Rows[n]["SumIntegral"].ToString() != "")
                    {
                        model.SumIntegral = int.Parse(dt.Rows[n]["SumIntegral"].ToString());
                    }
                    if (dt.Rows[n]["SurplusIntegral"].ToString() != "")
                    {
                        model.SurplusIntegral = int.Parse(dt.Rows[n]["SurplusIntegral"].ToString());
                    }
                    model.FromUserName = dt.Rows[n]["FromUserName"].ToString();
                    if (dt.Rows[n]["CreateDate"].ToString() != "")
                    {
                        model.CreateDate = DateTime.Parse(dt.Rows[n]["CreateDate"].ToString());
                    }
                    model.Store = dt.Rows[n]["Store"].ToString();
                    if (dt.Rows[n]["LAST_DATE"].ToString() != "")
                    {
                        model.LAST_DATE = DateTime.Parse(dt.Rows[n]["LAST_DATE"].ToString());
                    }
                    model.YZM = dt.Rows[n]["YZM"].ToString();
                    model.REMARK = dt.Rows[n]["REMARK"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获取会员号
        /// </summary>
        /// <returns></returns>
        public string GetPersonNo()
        {
            return dao.GetPersonNo();
        }

        /// <summary>
        /// 获取区域
        /// </summary>
        /// <returns></returns>
        public DataSet GetCityCode()
        {
            return dao.GetCityCode();
        }

    }
}
